package easyScript.start;

import javafx.application.Application;
import javafx.application.Platform;

import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import org.example.jnautil.key.KeyBoardManager;
import org.example.jnautil.key.RegisteredKey;

import java.util.List;

public class AppMain extends Application {


    PluginController pluginController =   PluginController.INSTANCE;

    BorderPane root;
    public static void main(String[] args) throws Exception {
        List<RegisteredKey> registeredKeys = KeyBoardManager.getInstance().allListener();
        System.out.println(registeredKeys);
        Application.launch(args);

    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        root = new BorderPane();
        root.setTop(crtTopMenu());

        root.centerProperty().bindBidirectional(pluginController.centerNode);
        pluginController.switch2pluginsView();
        Scene scene = new Scene(root, 800, 800);
//        scene.setOnKeyPressed(System.out::println);
        scene.setFill(null);
        primaryStage.setTitle("偷懒神器");
        primaryStage.setScene(scene);
        primaryStage.show();
        primaryStage.setAlwaysOnTop(false);
        primaryStage.setOnCloseRequest(event -> {
            Platform.exit();
            System.exit(0);
        });
    }

    // 顶部菜单栏
    Node crtTopMenu() {
        MenuBar menuBar = new MenuBar();

        Menu fileMenu = new Menu("File");
        Menu editMenu = new Menu("Edit");
        Menu helpMenu = new Menu("Help");

        menuBar.getMenus().addAll(fileMenu, editMenu, helpMenu);
        return menuBar;
    }


}